package com.dexilaonian.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.dexilaonian.R;
import com.dexilaonian.adpter.RecoveryAdapter;
import com.dexilaonian.fragment.ProjectFragment;
import com.dexilaonian.fragment.YiyangFragment;
import com.dexilaonian.ui.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class RecoveryActivity extends BaseActivity implements View.OnClickListener{
	String[] titles = new String[]{"康养项目","康养医师"};
	@Bind(R.id.recovery_v1)
	View recoveryV1;
	@Bind(R.id.recovery_v2)
	View recoveryV2;
	private List<Fragment> fragments_list = new ArrayList<>();
	@Bind(R.id.back)
	ImageView back;
	@Bind(R.id.et_sou_text)
	EditText  etSouText;
	@Bind(R.id.tv_search)
	TextView  tvSearch;
	@Bind(R.id.recovery_project)
	TextView  recoveryProject;
	@Bind(R.id.recoveryyishi)
	TextView  recoveryyishi;
	@Bind(R.id.recovery_viewpager)
	ViewPager recoveryViewpager;
	private ProjectFragment projectFragment;
	private YiyangFragment  yiyangFragment;
	private RecoveryAdapter recoveryAdapter;
	private String          city;


	@Override
	public int getLayoutID() {
		return R.layout.activity_recovery;
	}

	@Override
	public void initView() {
		projectFragment = new ProjectFragment();
		yiyangFragment = new YiyangFragment();
		fragments_list.add(projectFragment);
		fragments_list.add(yiyangFragment);
		recoveryAdapter = new RecoveryAdapter(RecoveryActivity.this.getSupportFragmentManager(),
											  fragments_list);

	}

	@Override
	protected void initData() {

	}



	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ButterKnife.bind(this);
		Intent intent = getIntent();
		city = intent.getStringExtra("City");
		Log.e("TTTcity", city);
		recoveryProject.setOnClickListener(this);
		recoveryyishi.setOnClickListener(this);

		recoveryViewpager.setAdapter(recoveryAdapter);
		recoveryViewpager.setCurrentItem(0);
		recoveryViewpager.setOffscreenPageLimit(2);
		recoveryViewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
			@Override
			public void onPageScrolled(int position, float positionOffset,int positionOffsetPixels){
			}

			@Override
			public void onPageSelected(int position) {
				changeTextColor(position);
			}

			@Override
			public void onPageScrollStateChanged(int state) {

			}
		});
	}

	private void changeTextColor(int position) {
		if (position == 0) {
			recoveryProject.setTextColor(Color.parseColor("#009a99"));
			recoveryyishi.setTextColor(Color.parseColor("#333333"));
			recoveryV1.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
			recoveryV2.setBackground(null);

		} else if (position == 1) {
			recoveryyishi.setTextColor(Color.parseColor("#009a99"));
			recoveryProject.setTextColor(Color.parseColor("#333333"));
			recoveryV1.setBackground(null);
			recoveryV2.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
		}
	}

	@OnClick({R.id.back,
			  R.id.tv_search,
			  R.id.recovery_project,
			  R.id.recoveryyishi})
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.back:
				finish();
				break;
		/*	case R.id.tv_search:
				break;*/
			case R.id.recovery_project:
				recoveryViewpager.setCurrentItem(0);
				recoveryProject.setTextColor(Color.parseColor("#009a99"));
				recoveryyishi.setTextColor(Color.parseColor("#333333"));
				recoveryV1.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
				recoveryV2.setBackground(null);
				break;
			case R.id.recoveryyishi:
				recoveryViewpager.setCurrentItem(1);
				recoveryyishi.setTextColor(Color.parseColor("#009a99"));
				recoveryProject.setTextColor(Color.parseColor("#333333"));
				recoveryV1.setBackground(null);
				recoveryV2.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
				break;
		}
	}
}
